//验证数据库中的用户相关内容
const User = {
  //查询用户手机号
  queryUserTel(option) {
    return "select * from user where tel = " + option.userTel + " ";
  },

  //查询密码
  queryUserPwd(option) {
    return (
      "select * from user where ( tel = " +
      option.userTel +
      ") and pwd=" +
      option.userPwd +
      " "
    );
  },

  //新增用户
  inserData(option) {
    let userTel = option.userTel;
    let userPwd = option.userPwd || "666666";

    //引入jwt Token包
    const jwt = require("jsonwebtoken");
    //用户信息
    let payload = { tel: userTel };

    //口令(密钥)
    let secret = "xxxccc445sdf##";
    //生成token
    let token = jwt.sign(payload, secret, { expiresIn: 120 });

    return (
      ' insert into user (tel, pwd, imgUrl, nickName, token) value (" ' +
      userTel +
      ' ", "' +
      userPwd +
      '", "https://img.tea7.com/0010445_0.jpeg?x-oss-process=image/resize,w_800", "' +
      userTel +
      '", "' +
      token +
      '") '
    );
  },
};

exports = module.exports = User;
